#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <time.h>

#include "menu.h"
#include "list.h"
#include "song.h"


int Menu()
{
	int c ;
	printf("          my mplayer\n");
	printf("=============================\n");
	printf("      1: 歌单操作\n");
	printf("      2: 播放控制\n");
	printf("      3: 音量控制\n");
	printf("      4: 退出播放器\n");
	printf("=============================\n");
	printf("\n请选择:");
	scanf("%d",&c);
	getchar();
	while(c < 0||c > 4)
	{
		printf("请重新输入:");
		scanf("%d%*c",&c);
		getchar();
	}
	return c ;

}

int singing_list_Menu()
{
	int c ;
	printf("          歌单操作\n");
	printf("=============================\n");
	printf("      1: 添加歌曲\n");
	printf("      2: 添加文件夹\n");
	printf("      3: 删除歌曲\n");
	printf("      4: 查看所有歌曲\n");
	printf("      5: 返回上一级\n");
	printf("=============================\n");
	printf("\n请选择:");
	scanf("%d",&c);
	getchar();
	while(c < 0||c > 5)
	{
		printf("请重新输入:");
		scanf("%d",&c);
		getchar();
	}
	return c ;
}


int play_control_Menu()
{
	int c ;
	Sing *p;
	printf("          播放控制\n");
	printf("=============================\n");
	printf("      1: 播放歌曲\n");
	printf("      2: 上一曲\n");
	printf("      3: 下一曲\n");
	printf("      4: 播放指定歌曲\n");
	printf("      5: 暂停/继续播放\n");
	printf("      6: 快进\n");
	printf("      7: 快退\n");
	printf("      8: 返回上一级\n");
	printf("=============================\n");
	p = read_singlist();
	show_sing(p);
	printf("\n请选择:");
	scanf("%d",&c);
	getchar();
	while(c < 0||c > 8)
	{
		printf("请重新输入:");
		scanf("%d",&c);
		getchar();
	}
	return c ;
}

int volume_control_Menu()
{
	int c ;
	printf("          音量控制\n");
	printf("=============================\n");
	printf("      1: 静音\n");
	printf("      2: 取消静音\n");
	printf("      3: 设置音量\n");
	printf("      4: 返回上一级\n");
	printf("=============================\n");
	printf("\n请选择:");
	scanf("%d",&c);
	getchar();
	while(c < 0||c > 4)
	{
		printf("请重新输入:");
		scanf("%d",&c);
		getchar();
	}
	return c ;
}


void singing_list()
{
	int c,loop = 1;
	Sing *so;
	while(loop)
	{
		system("clear");
		c = singing_list_Menu();
		switch(c)
		{
			case 1:	
				tianjia_sing();					
				break;
			case 2:					
				break;
			case 3:	
				remove_sing();				
				break;
			case 4:	
				so = read_singlist();
				show_sing(so);
				printf("输入任意指令以继续:\n");
				getchar();
				break;
			case 5:										
			default:
				loop = 0;
				break;
		}
	}
}

void play_control()
{
	int c,loop = 1;
	Sing *singing;
	while(loop)
	{
		system("clear");
		c = play_control_Menu();
		switch(c)
		{
			case 1:	
				singing = play_song();
				getchar();					
				break;
			case 2:	
				singing = last_song(singing);
				getchar();				
				break;
			case 3:	
				singing = next_sing(singing);
				getchar();				
				break;
			case 4:	
				singing = play_a_song();
				getchar();				
				break;
			case 5:	
				send_message("pause\n");
				getchar();
				break;
			case 6:	
				fast_forward();
				break;
			case 7:
				back_forward();
				break;
			case 8:								
			default:
				loop = 0;
				break;
		}
	}
}

void volume_control()
{
	int c,loop = 1;
	while(loop)
	{
		system("clear");
		c = volume_control_Menu();
		switch(c)
		{
			case 1:	
				send_message("mute 1\n");
				getchar();					
				break;
			case 2:	
				send_message("mute 0\n");
				getchar();					
				break;
			case 3:	
				set_volume();				
				break;
			case 4:																			
			default:
				loop = 0;
				break;
		}
	}
}


